<%-- 
    Document   : operador
    Created on : 17-feb-2012, 4:07:16
    Author     : Daniel
--%>

<%@page import="java.sql.SQLException"%>
<%@page import="escom.ipn.modelo.dto.coordenadaIncidenteClass"%>
<%@page import="escom.ipn.modelo.dto.CoordenadaPieTierraClass"%>
<%@page import="java.util.List"%>
<%@page import="escom.ipn.modelo.delegate.cooerdenadaIncidenteDelegate"%>
<%@page import="escom.ipn.modelo.delegate.CoordenadaRecursoDelegate"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Operador 066</title>     
    </head>
      
    <body >
        <div id="map_canvas1" style="width:100%; height:400px"></div>
        <div name="code" id="code">
             <%        
                     String script="";
                        HttpSession sess = request.getSession(true);
                        cooerdenadaIncidenteDelegate del = new cooerdenadaIncidenteDelegate();
                        CoordenadaRecursoDelegate recursoDel=new CoordenadaRecursoDelegate();
                        CoordenadaRecursoDelegate recursoPatrulla=new CoordenadaRecursoDelegate();
                        try{
                          coordenadaIncidenteClass incidente=new coordenadaIncidenteClass();
                          CoordenadaPieTierraClass recurso=new CoordenadaPieTierraClass();
                          incidente.setId(sess.getAttribute("idIncidente").toString());
                          recurso.setId(sess.getAttribute("idIncidente").toString());
                          incidente=del.mostrar(incidente);
         
                          script="<script type=\"text/javascript\">\n";
                          script+="var locations=[\n";
                          script+="['"+incidente.getLatitude().toString()+"','"+incidente.getLongitude().toString()+"','"+incidente.getEstado()+"','"+incidente.getNombreIncidente()+"','"+incidente.getId()+"']";
                          script+="];\n";
                         
                          List listaRecursos=recursoDel.mostrar(recurso);
                            
                            script+="var policias=[\n";

                            for (int i = 0; i < listaRecursos.size(); i++) 
                            {
                                    CoordenadaPieTierraClass coordenadasRecursos = (CoordenadaPieTierraClass) listaRecursos.get(i);  
                                    if(listaRecursos.size()<=1 || i==listaRecursos.size()-1)
                                    script+="['"+coordenadasRecursos.getLatitude().toString()+"','"+coordenadasRecursos.getLongitude().toString()+"','"+coordenadasRecursos.getEstado()+"','"+coordenadasRecursos.getNombreRecurso()+"']";
                                    else
                                    script+="['"+coordenadasRecursos.getLatitude().toString()+"','"+coordenadasRecursos.getLongitude().toString()+"','"+coordenadasRecursos.getEstado()+"','"+coordenadasRecursos.getNombreRecurso()+"'],";
                            }  
                           script+="];\n";
                                   
                         List listaPatrullas=recursoPatrulla.mostrarPatrulla(recurso);
                         script+="var patrullas=[\n";

                            for (int i = 0; i < listaPatrullas.size(); i++) 
                            {
                                    CoordenadaPieTierraClass coordenadasPatrullas = (CoordenadaPieTierraClass) listaPatrullas.get(i);  
                                    if(listaPatrullas.size()<=1 || i==listaPatrullas.size()-1)
                                    script+="['"+coordenadasPatrullas.getLatitude().toString()+"','"+coordenadasPatrullas.getLongitude().toString()+"','"+coordenadasPatrullas.getEstado()+"','"+coordenadasPatrullas.getNombreRecurso()+"']";
                                    else
                                    script+="['"+coordenadasPatrullas.getLatitude().toString()+"','"+coordenadasPatrullas.getLongitude().toString()+"','"+coordenadasPatrullas.getEstado()+"','"+coordenadasPatrullas.getNombreRecurso()+"'],";
                            }  
                         script+="];\n";
                         
                         script+=" var map = new google.maps.Map(document.getElementById('map_canvas1'), {\n"
                                +"zoom: 12,\n"
                                +"center: new google.maps.LatLng(19.433128561292573, -99.13234523352054),\n"
                                +"mapTypeId: google.maps.MapTypeId.ROADMAP\n"
                                +"});\n"
                                +" var marker;\n"
                                
                                //INCIDENTES
                                +"for (var i = 0; i < locations.length; i++) { \n"
                                +"var object=locations[i];\n"
                                +"var myLatLng = new google.maps.LatLng(object[0], object[1]);"
                                +"marker = new google.maps.Marker({\n"
                                +"position: myLatLng,\n"
                                +" map: map\n"
                                +" });\n"
                                +"if(object[2]=='Sin Atender')"
                                +"marker.setIcon('../img/rojo.png');\n"
                                +"else if(object[2]=='En Proceso')\n"
                                +"marker.setIcon('../img/amarillo.png');\n"
                                +"else\n"
                                +"marker.setIcon('../img/verde.png');\n"
                                +" attachInfo(marker,object[2],object[3],object[4]);\n"
                                +"}\n"
                                + "function attachInfo(marker, estado,nombre,id) {\n"
                                + "var infowindow = new google.maps.InfoWindow(\n"
                                + "{ content: '<h3 align=LEFT>Id: '+id+'</h3><h4 align=LEFT>Incidente: '+nombre+'</h4><h4 align=LEFT>Estado: '+estado+'</h4>'\n"
                                + "});\n"
                                + " google.maps.event.addListener(marker, 'click', function() {\n"
                                + " infowindow.open(map,marker);\n"
                                + "});\n"
                                + "}\n"
                                
                                //RECURSOS
                                 +"for (var i = 0; i < policias.length; i++) { \n"
                                    +"var object=policias[i];\n"
                                    +"var myLatLng = new google.maps.LatLng(object[0], object[1]);"
                                    +"marker = new google.maps.Marker({\n"
                                    +"position: myLatLng,\n"
                                    +" map: map\n"
                                    +" });\n"                                   
                                    +"if(object[2]=='En Evento')"
                                    +"marker.setIcon('../img/Policeman(2).png');\n"
                                    +"else if(object[2]=='En Camino')\n"
                                    +"marker.setIcon('../img/Policeman(1).png');\n"
                                    +"else\n"
                                    +"marker.setIcon('../img/Policeman.png');\n"       
                                    +" attachInfoPolice(marker,object[2],object[3]);\n"
                                    +"}\n"
                                    + "function attachInfoPolice(marker, estado,nombre) {\n"
                                    + "var infowindow = new google.maps.InfoWindow(\n"
                                    + "{ content: '<h3 align=LEFT>Nombre: '+nombre+'</h3><h4 align=LEFT>Estado: '+estado+'</h4>'\n"
                                    + "});\n"
                                    + " google.maps.event.addListener(marker, 'click', function() {\n"
                                    + " infowindow.open(map,marker);\n"
                                    + "});\n"
                                    + "}\n"  
                                    
                                //PATRULLAS
                                 +"for (var i = 0; i < patrullas.length; i++) { \n"
                                    +"var object=patrullas[i];\n"
                                    +"var myLatLng = new google.maps.LatLng(object[0], object[1]);"
                                    +"marker = new google.maps.Marker({\n"
                                    +"position: myLatLng,\n"
                                    +" map: map\n"
                                    +" });\n"                                   
                                    +"marker.setIcon('../img/Patrol.png');\n"       
                                    +" attachInfoPolice(marker,object[2],object[3]);\n"
                                    +"}\n"
                                    + "function attachInfoPolice(marker, estado,nombre) {\n"
                                    + "var infowindow = new google.maps.InfoWindow(\n"
                                    + "{ content: '<h3 align=LEFT>Nombre: '+nombre+'</h3><h4 align=LEFT>Estado: '+estado+'</h4>'\n"
                                    + "});\n"
                                    + " google.maps.event.addListener(marker, 'click', function() {\n"
                                    + " infowindow.open(map,marker);\n"
                                    + "});\n"
                                    + "}\n"
                                +"</script>\n";
                          out.println(script);
       
                        }catch(SQLException e){out.println(e.toString());}
                         
                %>     
        </div>
    </body>
</html>
